Bit Manipulation LeetCode Questions
-
Number of 1 Bits - Write a function that takes an unsigned integer and returns the number of '1' bits it has (also known as the Hamming weight).
-
Power of Two - Given an integer, write a function to determine if it is a power of two.
-
Counting Bits - Given a non negative integer number num, for every numbers i in the range 0 ≤ i ≤ num calculate the number of 1's in their binary representation and return them as an array.
-
Reverse Bits - Reverse bits of a given 32 bits unsigned integer.
-
Single Number - Given a non-empty array of integers, every element appears twice except for one. Find that single one.
-
Single Number II - Given a non-empty array of integers, every element appears three times except for one, which appears exactly once. Find that single one.
-
Single Number III - Given an array of numbers nums, in which exactly two elements appear only once and all the other elements appear exactly twice. Find the two elements that appear only once.
-
Sum of Two Integers - Calculate the sum of two integers a and b, but you are not allowed to use the operator + and -.
-
Missing Number - Given an array containing n distinct numbers taken from 0, 1, 2, ..., n, find the one that is missing from the array.
-
Repeated DNA Sequences - All DNA is composed of a series of nucleotides abbreviated as 'A', 'C', 'G', and 'T', finds all the 10-letter-long sequences (substrings) that occur more than once in a DNA molecule.
-
Bitwise AND of Numbers Range - Given a range [m, n], return the bitwise AND of all numbers in this range, inclusive.
-
UTF-8 Validation - A character in UTF8 can be from 1 to 4 bytes long. Given an array of integers representing the data, return whether it is a valid utf-8 encoding.
-
Total Hamming Distance - The Hamming distance between two integers is the number of positions at which the corresponding bits are different.
-
Binary Watch - A binary watch has 4 LEDs on the top which represent the hours (0-11), and the 6 LEDs on the bottom represent the minutes (0-59).
-
Maximum XOR of Two Numbers in an Array - Given an array of numbers, find the maximum result of ai XOR aj, where 0 ≤ i, j < n.
-
Find the Difference - Given two strings s and t which consist of only lowercase letters. String t is generated by random shuffling string s and then add one more letter at a random position. Find the letter that was added in t.
-
Binary Number with Alternating Bits - Given a positive integer, check whether it has alternating bits: namely, if two adjacent bits will always have different values.
-
Complement of Base 10 Integer - Every non-negative integer N has a binary representation. The complement of a number is the number you get when you flip every bit in its binary representation.
-
Binary Gap - Given a positive integer N, find and return the longest distance between two consecutive 1's in the binary representation of N.
-
Convert Binary Number in a Linked List to Integer - Given head which is a reference node to a singly-linked list. The value of each node in the linked list is either 0 or 1.
-
XOR Operation in an Array - Given an integer n and an integer start, define an array nums where nums[i] = start + 2*i (0-indexed) and n == nums.length. Return the bitwise XOR of all elements of nums.
-
Find XOR Sum of All Pairs Bitwise AND - Given two arrays nums1 and nums2, find the XOR sum of all pairs bitwise AND.
-
Sum of All Subset XOR Totals - The XOR total of an array is defined as the bitwise XOR of all its elements.
-
Minimum XOR Sum of Two Arrays - You are given two integer arrays nums1 and nums2 of length n. Return the minimum possible XOR sum of pairs of integers.
-
Check If a String Contains All Binary Codes of Size K - Given a binary string s and an integer k, return true if every binary code of length k is a substring of s.
-
Decode XORed Array - Given an encoded array where encoded[i] = arr[i] XOR arr[i + 1], return the original array arr.
-
Minimum One Bit Operations to Make Integers Zero - Given an integer n, you must transform it into 0 using the minimum number of one bit operations you can perform.
-
Maximum XOR for Each Query - You are given a sorted array and an integer, return the maximum XOR value for each query.
-
Maximum Product of Splitted Binary Tree - Given a binary tree, split the binary tree into two subtrees by removing one edge such that the product of the sums of the subtrees is maximized.
-
Maximum Good People Based on Statements - Given a list of statements about people, return the maximum number of good people based on the statements.